package me.zhengjie.modules.system.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.system.domain.SafeRiskCase;
import me.zhengjie.modules.system.service.SafeTestCaseService;
import me.zhengjie.modules.system.vo.SafeRiskTypeVo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * SafeTestItemController
 *
 * @author guoyuan
 * @version 1.0.0
 * @since 1.0.0
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "安全规则：场景风险案例")
@RequestMapping("/api/safeTestCase")
public class SafeTestCaseController {

    private final SafeTestCaseService safeRiskCaseService;

    @ApiOperation("所有场景风险案例列表查询")
    @GetMapping
    @PreAuthorize("@el.check('testCase:list')")
    public ResponseEntity<Object> queryAll(@RequestParam("sceneType") String sceneType) throws Exception {
        return new ResponseEntity<>(safeRiskCaseService.queryAll(sceneType), HttpStatus.OK);
    }
    @ApiOperation("通过caseid查询详细信息")
    @PostMapping("/queryById")
    @PreAuthorize("@el.check('testCase:list')")
    public ResponseEntity<Object> queryByCaseId(@RequestParam("caseId") String caseId) throws Exception {
        return new ResponseEntity<>(safeRiskCaseService.queryByCaseId(caseId), HttpStatus.OK);
    }
    @ApiOperation("通过caseid查询详细信息")
    @PostMapping("/queryByIds")
    @PreAuthorize("@el.check('testCase:lists')")
    public ResponseEntity<Object> queryByCaseIds(@RequestParam("caseIds") String caseIds) throws Exception {
        return new ResponseEntity<>(safeRiskCaseService.queryByCaseIds(caseIds), HttpStatus.OK);
    }

    @ApiOperation("新增场景风险案例")
    @PostMapping("/create")
    @PreAuthorize("@el.check('testCase:create')")
    public ResponseEntity<Object> creat(@RequestBody SafeRiskCase entity) {
        safeRiskCaseService.create(entity);
        return new ResponseEntity<>( HttpStatus.OK);
    }

    @ApiOperation("更新场景风险案例")
    @PutMapping("/update")
    @PreAuthorize("@el.check('testCase:update')")
    public ResponseEntity<Object> update(@RequestBody SafeRiskCase entity) throws Exception {
        safeRiskCaseService.update(entity);
        return new ResponseEntity<>( HttpStatus.OK);
    }
    @ApiOperation("所有测试类型列表查询")
    @DeleteMapping("/delete")
    @PreAuthorize("@el.check('testCase:delete')")
    public ResponseEntity<Object> delete(SafeRiskTypeVo vo) throws Exception {
        safeRiskCaseService.delete(vo.getId());
        return new ResponseEntity<>( HttpStatus.OK);
    }

}
